Ext.user.method = {};
Ext.user.method.did = function(){	
	var store = new Ext.data.JsonStore({
		idProperty: "did",
		fields: ['name','did'],
		url: Ext.user.baseUrl + '/User/data/',
		baseParams:{'do':'did'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.comid = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + '/User/data/',
		baseParams:{'do':'type'},
		autoLoad:true
		//data:Ext.user.data.roleid
	});
	return store;
}
Ext.user.method.workuser = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + '/Work/data/',
		baseParams:{'do':'userid'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.chartgroup = function(){
	var store = new Ext.data.JsonStore({
		fields: ['did','name'],
		url: Ext.user.baseUrl + '/Chart/data/',
		baseParams:{'do':'groupid'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.chartuser = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + '/Chart/data/',
		baseParams:{'do':'userid'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.roleid = function(n){
	if(!n) n = '/User/data/';
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + n,
		baseParams:{'do':'roleid'},
		autoLoad:true
		//data:Ext.user.data.roleid
	});
	return store;
}
Ext.user.method.date = function(n){
	if(n != '')
	return '<p>' + new Date(n).dateFormat('Y/m/d H:i:s') + '</p>';
}
Ext.user.method.dates = function(n){
	var date = new Date(n);
	if(date.dateFormat('Y') == 1970) return '没有排班';
	if(n != '')
	return '<p>' + date.dateFormat('Y/m/d') + '</p>';
}
Ext.user.method.groupid = function(){
	//p/Node/data/',array('do'=>'groupid'));?>;
	var store = new Ext.data.JsonStore({
		storeId:'groupid',
		fields: ['id','title'],
		url: Ext.user.baseUrl + '/Node/data/',
		baseParams:{'do':'groupid'},
		autoLoad:true
	});
	
	return store;
}

Ext.user.method.grouproleid = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + '/Role/data/',
		baseParams:{'do':'grouprole'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.cityid = function(n){
	if(!n) n = '/City/data/';
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + n,
		baseParams:{'do':'city'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.binzhongid = function(n){
	if(!n) n = '/Binzhong/data/';
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + n,
		baseParams:{'do':'binzhong'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.usercityid = function(n){
	if(!n) n = '/City/data/';
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + n,
		baseParams:{'do':'usercity'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.userbinzhongid = function(n){
	if(!n) n = '/Binzhong/data/';
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		url: Ext.user.baseUrl + n,
		baseParams:{'do':'userbinzhong'},
		autoLoad:true
	});
	return store;
}
Ext.user.method.qudao = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		data:[{'id':1,'name':'QQ'},{'id':2,'name':'网站客服'},{'id':3,'name':'电话'}]
	});
	return store;
}
Ext.user.method.sexid = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		data:[{'id':1,'name':'男'},{'id':2,'name':'女'}]
	});
	return store;
}

Ext.user.method.visitid = function(){
	var store = new Ext.data.JsonStore({
		fields: ['id','name'],
		data:[{id:1,'name':'已就诊'},{id:2,'name':'再联系'},{id:3,'name':'取消'},{id:4,'name':'改约'}]
	});
	return store;
}
Ext.user.method.group = function(n){
	if(n == 0) return '未知';
	var record = Ext.user.method.groupidstore;
	return record.getById(n).data.title;
}
Ext.user.method.role = function(n){
	if(n == 0) return '无上级组';
	var record = Ext.user.method.roleidstore;
	return record.getById(n).data.name;
}
Ext.user.method.userrole = function(n){
	if(n == 0) return '网络部';
	var record = Ext.user.method.didstore;
	return record.getById(n).data.name;
}
Ext.user.method.paibanid = function(n){
	var store = new Ext.data.JsonStore({
		 fields: ['id','text'],
		 data:[{'text':'早班','id':'1'},{'text':'中班','id':'2'},{'text':'晚班','id':'3'},{'text':'行政班','id':'4'}]
	});
	return store;
}
Ext.user.method.statusid = function(n){
	var store = new Ext.data.JsonStore({
		 fields: ['text','value'],
		 data:[{'text':'启用','value':'1'},{'text':'禁用','value':'0'}]
	});
	return store;
}
Ext.user.method.nodestatus = function(n){
	if(n == 1)
		return '<p  style="">启用</p>';
	else
		return '<p  style="color: #F00;">禁用</p>';
}
Ext.user.method.status = function(n){
	if(n == true)
		return '<p  style="">正常</p>';
	else
		return '<p  style="color: #F00;">锁定</p>';
}
Ext.user.method.loaddataForm = function(f){
		if(f.method == undefined) f.method = 'GET';
		Ext.Ajax.request({
		   url: Ext.user.baseUrl + f.url,
		   method:f.method,
		   callback:function(o,s,r){
				var data = Ext.util.JSON.decode(r.responseText);
				var Record = Ext.data.Record.create(f.recorddata);
				//var dataform = Ext.getCmp(f.Formid);
				Ext.getCmp(f.Formid).form.loadRecord(new Record(data));
		   },
		   params: f.params
		});

}
Ext.user.method.submitData = function(f){
		if(f.method == undefined) f.method = 'POST';
		Ext.Ajax.request({
		   url: Ext.user.baseUrl + f.url,
		   method:f.method,
		   callback:function(o,s,r){
				//var data = Ext.util.JSON.decode(r.responseText);
		   },
		   params: f.params,
		   jsonData:f.Data
		});

}
Ext.user.method.submitForm = function(f,baseurl,datainfo,method,waitmsg){
	method = method == 'POST' ? method : 'GET';
	waitmsg = waitmsg == '' ? 'posting...' : waitmsg;
	Ext.getCmp(f).form.submit({
		method: method,
		url:Ext.user.baseUrl + baseurl,
	    waitMsg: waitmsg,
		success: function(f, a){
			if(typeof datainfo !== 'undefined' && datainfo != '')
			{
				datainfo.s(f,a);
			}
		},
		failure: function(f,a){
			if(typeof datainfo !== 'undefined' && datainfo != '')
			{
				datainfo.f(f,a);
			}
		}
	});
}
Ext.user.method.json = function(Extdata){
	var json = {};
	for(var i =0;i<Extdata.length;i++)
	{
		if(Extdata[i].data != '') json[i] = Extdata[i].data;
	}
	return Ext.util.JSON.encode(json);
}
Ext.user.method.nodechange = function(n){
	var g = Ext.getCmp('nodelist');
	if(n != 0 )
	{
		g.getStore().load({
			params:{'do':'typeid','groupid':n}
		});
	}
	else
	{
		g.getStore().load();
	}

}

Ext.user.method.store = function(fileds,data){
    var store = new Ext.data.ArrayStore({
        fields: fileds,
        data : data
    });
		return store;
}
Ext.user.tpl = {};
Ext.user.tpl.nodetbar = '<div style="margin-bottom:5px;margin-left:30px;line-height: 20px;"><tpl for="."><a href="javascript:Ext.user.method.nodechange({id})" >{title}</a>&nbsp;|&nbsp;</tpl><a href="javascript:;" onclick="Ext.user.method.nodechange(0);">所有</a><p id="node_button"></p></div>';


Ext.user.renderer = {};
Ext.user.renderer.binzhong = function(n){
	if(n == 0) return '未知病例';
	var record = Ext.user.method.binzhongidstore;
	return record.getById(n).data.name;
}
Ext.user.renderer.askway = function(n){
	if(n == 0) return '未知';
	var record = Ext.user.method.qudaostore;
	return record.getById(n).data.name;
}
Ext.user.renderer.sex = function(n){
	if(n == 0 || n ==null) return '未知';
	var record = Ext.user.method.sexidstore;
	return record.getById(n).data.name;
}
Ext.user.renderer.visit = function(n){
	if(n == 0) return '未知';
	var record = Ext.user.method.visitidstore;
	return record.getById(n).data.name;
}
Ext.user.renderer.paiban = function(n){
	if(typeof n == 'undefined' || n == 0 || n == null) return '未知';
	if(n == 0) return '未知';
	var record = Ext.user.method.paibanidstore;
	return record.getById(n).data.text;
}
Ext.user.addnode = function(id,n){
	Ext.getCmp(id).root.appendChild(new Ext.tree.TreeNode({
		did:n.did,
        text:n.name,
        leaf:true
   }));
}
Ext.user.deletenode = function(id,n){
	Ext.getCmp(id).root.removeChild(new Ext.tree.TreeNode({
		did:n.id,
        leaf:true
   }));
}
Ext.user.deletenodeeditgrid = function(n){
	if(confirm('你确认要删除这条数据？')){
		var store = Ext.StoreMgr.lookup('nodeliststore');
		var rec = Ext.getCmp('nodelist').getSelectionModel().getSelected();
		store.remove(rec);
		store.reload();
	}
}
Ext.user.deleterolegrid = function(n){
	if(confirm('你确认要删除这条数据？')){
		var store = Ext.StoreMgr.lookup('RoleStore');
		var rec = Ext.getCmp('rolelist').getSelectionModel().getSelected();
		store.remove(rec);
		store.reload();
	}
}
Ext.user.deleteusergrid = function(n){
	if(confirm('你确认要删除这个账号？')){
		var store = Ext.StoreMgr.lookup('UserStore');
		var rec = Ext.getCmp('userlisteditgrid').getSelectionModel().getSelected();
		store.remove(rec);
		store.reload();
	}
}
Ext.user.method.dateday = function(n,m){
	var date = new Date(n);
	return date.add(Date.DAY,m);
}
Ext.user.rabc = function(m){
	var Rabc = new Ext.user.RabcWindow({roleid:m});
	Rabc.show();
	Ext.getCmp('Rabcform').add(new Ext.form.Hidden({renderTo:'RabcformId',name:'rid',value:m}));
   /* Ext.user.method.loaddataForm({
		url:'/Role/data/',
		params:{do:'roleid',roleid:m},
		Formid:'Rabcform',
		method:'POST',
		recorddata:['roleid']
	});
	*/
		//Ext.getCmp('Rabcform').form.setValues({'roleid':39});
}
Ext.user.alert = function(m){
 Ext.MessageBox.show({
           title: m.info,
           msg: m.data,
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: 'ext-mb-' + (m.success == 0 ? 'error' : 'info')
       });
}